module Piston
  module Output
    class OutputTextBox
      def initialize(main_window)
        @text_box = main_window.find_name('output')
      end

      def write(msg)
        @text_box.dispatcher.invoke(
          System::Windows::Threading::DispatcherPriority.Render,
          System::Action.new {
            @text_box.AppendText("#{msg}")
          }
        )
      end
      alias :print :write

      def puts(msg)
        write("#{msg}\n")
      end
    end
  end
end